

(function() {

    tinymce.create('tinymce.plugins.ajaxImagePlugin', {

        /**

* Initializes the plugin, this will be executed after the plugin has been created.

* This call is done before the editor instance has finished it's initialization so use the onInit event

* of the editor instance to intercept that event.

*

* @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.

* @param {string} url Absolute URL to where the plugin is located.

*/

        init : function(ed, url) {

            // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('mceExample');

            ed.addCommand('ajaxImage', function() {

                $('#uploadform')[0].reset();

                $("#overlay").fadeTo( 'fast', .6 ); 

                $('#upload_form').fadeIn('fast');

            });

 

            // Register button

            ed.addButton('ajaximage', {

                title : 'Upload Image',

                cmd : 'ajaxImage',

                image : url + '/img/image.gif'

            });

 

            // Add a node change handler, selects the button in the UI when a image is selected

            ed.onNodeChange.add(function(ed, cm, n) {

                cm.setActive('example', n.nodeName == 'IMG');

            });

        },

  

        /**

* Returns information about the plugin as a name/value array.

* The current keys are longname, author, authorurl, infourl and version.

*

* @return {Object} Name/value array containing information about the plugin.

*/

        getInfo : function() {

            return {

                longname : 'Ajax image upload plugin',

                author : 'Mike Hayes',

                authorurl : 'http://www.mikesimagination.net',

                infourl : 'http://www.mikesimagination.net',

                version : "1.0"

            };

        }

    });

 

    // Register plugin

    tinymce.PluginManager.add('ajaximage', tinymce.plugins.ajaxImagePlugin);

})();
